package com.itheima.health.security;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.*;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;

import java.util.HashMap;
import java.util.Map;
/**
 * @Author wangbowen
 * @Date 2020/2/26 11:16
 * @Version version 1.0
 * @Description 加密器工厂类
 */
public class MyPasswordEncoder {

    private static Map<String, PasswordEncoder> map=new HashMap<>();
    private static String encodingId = "bcrypt";
    public static DelegatingPasswordEncoder createDlegatingPasswordEncoder(){
        map.put(encodingId, new BCryptPasswordEncoder());
        map.put("MD4", new Md4PasswordEncoder());
        map.put("MD5", new MessageDigestPasswordEncoder("MD5"));
        map.put("noop", NoOpPasswordEncoder.getInstance());
        map.put("pbkdf2", new Pbkdf2PasswordEncoder());
        map.put("scrypt", new SCryptPasswordEncoder());
        map.put("SHA-1", new MessageDigestPasswordEncoder("SHA-1"));
        map.put("SHA-256", new MessageDigestPasswordEncoder("SHA-256"));
        DelegatingPasswordEncoder delegatingPasswordEncoder= new MyFinalPasswordEncoder(encodingId,map);
        delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(NoOpPasswordEncoder.getInstance());
        return delegatingPasswordEncoder;
    }
}
